package com.orkhonsoft.tengrinshar.chat.common;


import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 查询参数

 */
public class Query extends LinkedHashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	// 当前页码
    private int page = 1;
    // 每页条数
    private int limit = 20;
    // 排序字段
    private String orderby = "id";
    // 排序方式
    private String sort = "desc";

    public Query(Map<String, Object> params){
        this.putAll(params);

        //分页参数
        if(params.get("page") != null) {
        	this.page = Integer.parseInt(params.get("page").toString());
        }
        if(params.get("limit") != null) {
        	this.limit = Integer.parseInt(params.get("limit").toString());
        }
        if(params.get("orderby") != null) {
        	this.orderby = params.get("orderby").toString();
        }
        if(params.get("sort") != null) {
        	this.sort = params.get("sort").toString();
        }
        
        this.put("offset", (page - 1) * limit);
        this.put("page", page);
        this.put("limit", limit);

    }


    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }


	public String getOrderby() {
		return orderby;
	}


	public void setOrderby(String orderby) {
		this.orderby = orderby;
	}


	public String getSort() {
		return sort;
	}


	public void setSort(String sort) {
		this.sort = sort;
	}
    
    
}
